home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABERMUD.ZIP / BPRINTF.C < prev    next >
C/C++ Source or Header  |  1989-07-08  |  8KB  |  386 lines

  1. #include "files.h"
  2. #include <stdio.h>
  3. #include "System.h"
  4.  
  5. long pr_due=0;
  6.  
  7. void bprintf(args,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
  8. char *args,*arg1,*arg2,*arg3,*arg4,*arg5,*arg6,*arg7;
  9.     {
  10.     char x[256],a[40];  /* Max 240 chars/msg */
  11.     long ct;
  12.     sprintf(x,args,arg1,arg2,arg3,arg4,arg5,arg6);
  13. if(strlen(x)>235)
  14. {
  15. syslog("Bprintf Short Buffer overflow");
  16. crapup("Internal Error in BPRINTF");
  17. }
  18.     /* Now we have a string of chars expanded */
  19.     quprnt(x);
  20.     }
  21.  
  22.  /* The main loop */
  23.  
  24. void dcprnt(str,file)
  25.  char *str;
  26.  FILE *file;
  27.     {
  28.     long ct;
  29.     ct=0;
  30.     while(str[ct])
  31.        {
  32.        if(str[ct]!='\001'){fputc(str[ct++],file);continue;}
  33.        ct++;
  34.        switch(str[ct++])
  35.           {
  36.           case 'f':
  37.              ct=pfile(str,ct,file);continue;
  38.           case 'd':
  39.              ct=pndeaf(str,ct,file);continue;
  40.           case 's':
  41.              ct=pcansee(str,ct,file);continue;
  42.           case 'p':
  43.              ct=prname(str,ct,file);continue;
  44.           case 'c':
  45.              ct=pndark(str,ct,file);continue;
  46.           case 'P':
  47.              ct=ppndeaf(str,ct,file);continue;
  48.           case 'D':
  49.              ct=ppnblind(str,ct,file);continue;
  50.           case 'l':
  51.              ct=pnotkb(str,ct,file);continue;
  52.           default:
  53.              strcpy(str,"");
  54.              loseme();crapup("Internal $ control sequence error\n");
  55.              }
  56.        }
  57.     }
  58.  
  59. int pfile(str,ct,file)
  60.  char *str;
  61.  FILE *file;
  62.     {
  63.     extern long debug_mode;
  64.     char x[128];
  65.     ct=tocontinue(str,ct,x,128);
  66.     if(debug_mode) fprintf(file,"[FILE %s ]\n",str);
  67.     f_listfl(x,file);
  68.     return(ct);
  69.     }
  70.  
  71. int pndeaf(str,ct,file)
  72.  char *str;
  73.  FILE *file;
  74.     {
  75.     char x[256];
  76.     extern long ail_deaf;
  77.     ct=tocontinue(str,ct,x,256);
  78.     if(!ail_deaf)fprintf(file,"%s",x);
  79.     return(ct);
  80.     }
  81.  
  82.  pcansee(str,ct,file)
  83.  char *str;
  84.  FILE *file;
  85.     {
  86.     char x[25];
  87.     char z[257];
  88.     long a;
  89.     ct=tocontinue(str,ct,x,23);
  90.     a=fpbns(x);
  91.     if(!seeplayer(a))
  92.        {
  93.        ct=tocontinue(str,ct,z,256);
  94.        return(ct);
  95.        }
  96.     ct=tocontinue(str,ct,z,256);
  97.     fprintf(file,"%s",z);
  98.     return(ct);
  99.     }
  100.  
  101.  prname(str,ct,file)
  102.  char *str;
  103.  FILE *file;
  104.     {
  105.     char x[24];
  106.     ct=tocontinue(str,ct,x,24);
  107.     if(!seeplayer(fpbns(x)))
  108.     fprintf(file,"Someone");
  109.     else
  110.       fprintf(file,"%s",x);
  111.     return(ct);
  112.     }
  113.  
  114.  
  115. int pndark(str,ct,file)
  116.  char *str;
  117.  FILE *file;
  118.     {
  119.     char x[257];
  120.     extern long ail_blind;
  121.     ct=tocontinue(str,ct,x,256);
  122.     if((!isdark())&&(ail_blind==0))
  123.     fprintf(file,"%s",x);
  124.     return(ct);
  125.     }
  126.  
  127. int tocontinue(str,ct,x,mx)
  128.  char *str;
  129.  long ct;
  130.  char *x;
  131.  long mx;
  132.     {
  133.     long s;
  134.     s=0;
  135.     while(str[ct]!='\001')
  136.        {
  137.        x[s++]=str[ct++];
  138.        }
  139.     x[s]=0;
  140. if(s>=mx)
  141. {
  142. syslog("IO_TOcontinue overrun");
  143. strcpy(str,"");
  144. crapup("Buffer OverRun in IO_TOcontinue");
  145. }
  146.     return(ct+1);
  147.     }
  148.  
  149. int seeplayer(x)
  150.     {
  151.     extern long mynum;
  152.     extern long ail_blind;
  153.     extern long curch;
  154.     if(x==-1) return(1);
  155.     if(mynum==x) {return(1);} /* me */
  156.     if(plev(mynum)<pvis(x)) return(0);
  157.     if(ail_blind) return(0); /* Cant see */
  158.     if((curch==ploc(x))&&(isdark(curch)))return(0);
  159.     setname(x);
  160.     return(1);
  161.     }
  162. int ppndeaf(str,ct,file)
  163.  char *str;
  164.  FILE *file;
  165.     {
  166.     char x[24];
  167.     extern long ail_deaf;
  168.     long a;
  169.     ct=tocontinue(str,ct,x,24);
  170.     if(ail_deaf) return(ct);
  171.     a=fpbns(x);
  172.     if(seeplayer(a)) fprintf(file,"%s",x);
  173.     else
  174.       fprintf(file,"Someone");
  175.     return(ct);
  176.     }
  177.  
  178. int  ppnblind(str,ct,file)
  179. char *str;
  180. FILE *file;
  181.     {
  182.     extern long ail_blind;
  183.     char x[24];
  184.     long a;
  185.     ct=tocontinue(str,ct,x,24);
  186.     if(ail_blind) return(ct);
  187.     a=fpbns(x);
  188.     if(seeplayer(a)) fprintf(file,"%s",x);
  189.     else
  190.        fprintf(file,"Someone");
  191.     return(ct);
  192.     }
  193.  
  194. char *sysbuf=NULL;
  195.  
  196. void makebfr()
  197.     {
  198.     extern char *sysbuf;
  199.     extern char *malloc();
  200.     sysbuf=malloc(4096); /* 4K of chars should be enough for worst case */
  201.     if(sysbuf==NULL) crapup("Out Of Memory");
  202.     sysbuf[0]=0;
  203.     }
  204.     
  205. FILE * log_fl= 0; /* 0 = not logging */
  206.  
  207. void logcom()
  208.     {
  209.     extern FILE * log_fl;
  210.     extern char globme[];
  211.     if(getuid()!=geteuid()) {bprintf("\nNot allowed from this ID\n");return;}
  212.     if(log_fl!=0)
  213.        {
  214.        fprintf(log_fl,"\nEnd of log....\n\n");
  215.        fclose(log_fl);
  216.        log_fl=0;
  217.        bprintf("End of log\n");
  218.        return;
  219.        }
  220.     bprintf("Commencing Logging Of Session\n");
  221.     log_fl=fopen("mud_log","a");
  222.     if(log_fl==0) log_fl=fopen("mud_log","w");
  223.     if(log_fl==0)
  224.        {
  225.        bprintf("Cannot open log file mud_log\n");
  226.        return;
  227.        }
  228.     bprintf("The log will be written to the file 'mud_log'\n");
  229.     }
  230.  
  231. long pr_qcr; 
  232.  
  233. void pbfr()
  234.     {
  235.     FILE *fln;
  236.     long mu;
  237.     block_alarm();
  238.     closeworld();
  239.     if(strlen(sysbuf)) pr_due=1;
  240.     if((strlen(sysbuf))&&(pr_qcr)) putchar('\n');
  241.     pr_qcr=0;
  242.     if(log_fl!=NULL)
  243.        {
  244.        iskb=0;
  245.        dcprnt(sysbuf,log_fl);
  246.        }
  247.     if(snoopd!=-1)
  248.        {
  249.        fln=opensnoop(pname(snoopd),"a");
  250.        if(fln>0)
  251.           {
  252. iskb=0;
  253.           dcprnt(sysbuf,fln);
  254.           fcloselock(fln);
  255.           }
  256.        }
  257.     iskb=1;
  258.     dcprnt(sysbuf,stdout);
  259.     sysbuf[0]=0; /* clear buffer */
  260.     if(snoopt!=-1) viewsnoop();
  261.     unblock_alarm();
  262.     }
  263.  
  264. long iskb=1;
  265.  
  266. void quprnt(x)
  267.  char *x;
  268.     {
  269.     if((strlen(x)+strlen(sysbuf))>4095)
  270.        {
  271.        strcpy(sysbuf,"");
  272.        loseme();
  273.        syslog("Buffer overflow on user %s",globme);
  274.        crapup("PANIC - Buffer overflow");
  275.        }
  276.     strcat(sysbuf,x);
  277.     }
  278.  
  279. int pnotkb(str,ct,file)
  280.  char *str;
  281.  FILE *file;
  282.     {
  283.     extern long iskb;
  284.     char x[128];
  285.     ct=tocontinue(str,ct,x,127);
  286.     if(iskb) return(ct);
  287.     fprintf(file,"%s",x);
  288.     return(ct);
  289.     }
  290.  
  291. long snoopd= -1;
  292.  
  293. FILE *opensnoop(user,per)
  294. char *per;
  295. char *user;
  296.     {
  297.     FILE *x;
  298.     extern FILE *openlock();
  299.     char z[256];
  300.     sprintf(z,"%s%s",SNOOP,user);
  301.     x=openlock(z,per);
  302.     return(x);
  303.     }
  304.  
  305. long snoopt= -1;
  306.  
  307. char sntn[32];
  308.  
  309. void snoopcom()
  310.     {
  311.     FILE *fx;
  312.     long x;
  313.     if(my_lev<10)
  314.        {
  315.        bprintf("Ho hum, the weather is nice isn't it\n");
  316.        return;
  317.        }
  318.     if(snoopt!=-1)
  319.        {
  320.        bprintf("Stopped snooping on %s\n",sntn);
  321.        snoopt= -1;
  322.        sendsys(sntn,globme,-400,0,"");
  323.        }
  324.     if(brkword()== -1)
  325.        {
  326.        return;
  327.        }
  328.     x=fpbn(wordbuf);
  329.     if(x==-1)
  330.        {
  331.        bprintf("Who is that ?\n");
  332.        return;
  333.        }
  334.     if(((my_lev<10000)&&(plev(x)>=10))||(ptstbit(x,6)))
  335.        {
  336.        bprintf("Your magical vision is obscured\n");
  337.        snoopt= -1;
  338.        return;
  339.        }
  340.     strcpy(sntn,pname(x));
  341.     snoopt=x;
  342.     bprintf("Started to snoop on %s\n",pname(x));
  343.     sendsys(sntn,globme,-401,0,"");
  344.     fx=opensnoop(globme,"w");
  345.     fprintf(fx," ");
  346.     fcloselock(fx);
  347.     }
  348.  
  349. void viewsnoop()
  350.     {
  351.     long x;
  352.     char z[128];
  353.     FILE *fx;
  354.     fx=opensnoop(globme,"r+");
  355.     if(snoopt==-1) return;
  356.     if(fx==0)return;
  357.     while((!feof(fx))&&(fgets(z,127,fx)))
  358.            printf("|%s",z);
  359.     ftruncate(fileno(fx),0);
  360.     fcloselock(fx);
  361.     x=snoopt;
  362.     snoopt= -1;
  363.     /*
  364.     pbfr();
  365.     */
  366.     snoopt=x;
  367.     }
  368. void chksnp()
  369. {
  370. if(snoopt==-1) return;
  371. sendsys(sntn,globme,-400,0,"");
  372. }
  373.  
  374. void setname(x)  /* Assign Him her etc according to who it is */
  375. long x;
  376. {
  377.     if((x>15)&&(x!=fpbns("riatha"))&&(x!=fpbns("shazareth")))
  378.     {
  379.         strcpy(wd_it,pname(x));
  380.         return;
  381.     }
  382.     if(psex(x)) strcpy(wd_her,pname(x));
  383.     else strcpy(wd_him,pname(x));
  384.     strcpy(wd_them,pname(x));
  385. }
  386.